import { lazy } from "react";
import { Routeritem, Routerlist } from "../utils/type";
import { Localroutes } from "../utils/type";
//登录角色渲染
let paths = localStorage.getItem('routes') ? JSON.parse(localStorage.getItem('routes') as string) : ''


const renderpaths = (arr: Localroutes[]) => {
    let kpath: Routeritem[] = []
    arr && arr.forEach((item: Localroutes, index: number) => {
        if (item.childtype === 1) {
            kpath.push({
                id: item.id,
                path: item.path,
                element: lazy(() => import('../pages/' + item.element)),
                title: item.title,
                icon: item.icon,
                children: renderpaths(item.children as Localroutes[])
            })
        }
        else {
            kpath.push({
                id: item.id,
                path: item.path,
                element: lazy(() => import('../pages/' + item.element)),
                title: item.title,
                icon: item.icon,
            })
        }
    })
    return kpath
}
export const homeRoutes: Routeritem[] = renderpaths(paths)

//三级导航
// const testRoutes: Routeritem[] = [
//     {
//         id: 5,
//         path: "/home/test/page",
//         element: lazy(() => import('../pages/test/page')),
//         title: '页面',
//         icon: "DesktopOutlined"
//     },
//     {
//         id: 6,
//         path: "/home/test/role",
//         element: lazy(() => import('../pages/test/role')),
//         title: '角色',
//         icon: "FileOutlined"
//     }
// ]

// //二级导航
// export const homeRoutes: Routeritem[] = [
//     {
//         id: 1,
//         path: "/home/index",
//         element: lazy(() => import('../pages/index')),
//         title: '首页',
//         icon: "PieChartOutlined"
//     },
//     {
//         id: 2,
//         path: "/home/icon",
//         element: lazy(() => import('../pages/icon')),
//         title: '头像',
//         icon: "TeamOutlined"
//     },
//     {
//         id: 3,
//         path: "/home/table",
//         element: lazy(() => import('../pages/table')),
//         title: '表格',
//         icon: "UserOutlined"
//     },
//     {
//         id: 4,
//         path: "/home/test",
//         element: lazy(() => import('../pages/test')),
//         title: '测试',
//         children: testRoutes,
//         icon: "DesktopOutlined"
//     }
// ]

//一级导航
const routerlist: Routerlist = {
    mode: "history",
    routes: [
        {
            path: "/",
            to: '/home/index'
        },
        {
            path: "/home",
            element: lazy(() => import('../pages/home')),
            children: homeRoutes
        },
        {
            path: "/login",
            element: lazy(() => import('../pages/login'))
        },
        {
            path: "*",
            element: lazy(() => import('../pages/error'))
        }
    ]
}
export default routerlist